﻿using Model;
using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using DAL;
using System.Text;
using FubiManger.UI;
namespace FubiManger.Staff
{
    partial class StaffMianForm : Smobiler.Core.Controls.MobileForm
    {
        public StaffMianForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        /// <summary>
        /// 用户ID
        /// </summary>
        public string adminid { get; set; }
        /// <summary>
        /// 商户ID
        /// </summary>
        public string merchantid { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public string nickname { get; set; }
        /// <summary>
        /// 列表刷新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lvord_Refresh(object sender, EventArgs e)
        {
            List<ms_order> ordlist = orderDal.Querybysalesid(merchantid, adminid);//通过工作人员ID查订单
            Getorder(ordlist);
        }

        /// <summary>
        /// 获取订单
        /// </summary>
        private void Getorder(List<ms_order> ordlist)
        {

            if (lvord.Rows.Count > 0)
                lvord.Rows.Clear();
            DataTable table = new DataTable();
            table.Columns.Add("nickname");
            table.Columns.Add("ordid");
            table.Columns.Add("ordsn");
            table.Columns.Add("time");
            table.Columns.Add("disksn");
            table.Columns.Add("u_sage");
            table.Columns.Add("is_online");
            table.Columns.Add("stype");
            for (int i = 0; i < ordlist.Count; i++)
            {
                string nickname = "";
                if (ordlist[i].user_tel.Length == 11)
                    nickname = ordlist[i].user_tel.Substring(0, 3) + "****" + ordlist[i].user_tel.Substring(7, 4);
                table.Rows.Add(nickname, ordlist[i].id, ordlist[i].order_sn, ordlist[i].add_time, ordlist[i].orderdisksn, ordlist[i].u_sage, ordlist[i].is_online, "3");
            }
            lvord.DataSource = table;
            lvord.DataBind();
        }

        private void StaffMianForm_Load(object sender, EventArgs e)
        {
            List<ms_order> ordlist = orderDal.Querybysalesid(merchantid, adminid);//通过工作人员ID查订单
            Getorder(ordlist);
        }

        private void StaffMianForm_KeyDown(object sender, KeyDownEventArgs e)
        {
            if (e.KeyCode == KeyCode.Back)
            {

            }
        }

        private void tbmenu_ToolbarItemClick(object sender, ToolbarClickEventArgs e)
        {
            switch (e.Name)
            {
                case "ord":
                    tbmenu.SelectedIndex = 0;
                    break;
                case "ordfood":
                    List<ms_disk> disklist = diskDal.Querybymerid(merchantid);
                    if (disklist.Count > 0)
                    {
                        DisksForm frm = new DisksForm();
                        frm.merchantid = merchantid;//商户id
                        frm.adminid = adminid;
                        this.Form.Show(frm, true, (obj, args) =>
                        {
                            tbmenu.SelectedIndex = 0;
                            List<ms_order> ordlist = orderDal.Querybysalesid(merchantid, adminid);//通过工作人员ID查订单
                            Getorder(ordlist);
                        });
                    }
                    else
                    {
                        OrderfoodForm frm = new OrderfoodForm();
                        frm.merchantid = merchantid;//商户id
                        frm.adminid = adminid;//用户ID
                        this.Form.Show(frm, true, (obj, args) =>
                        {
                            tbmenu.SelectedIndex = 0; List<ms_order> ordlist = orderDal.Querybysalesid(merchantid, adminid);//通过工作人员ID查订单
                            Getorder(ordlist);
                        });
                    }

                    break;
                case "user":
                    StaffuserForn ufrm = new StaffuserForn();
                    ufrm.adminid = adminid;//用户ID
                    ufrm.nickname = nickname;//姓名
                    this.Form.Show(ufrm, true, (obj, args) => { tbmenu.SelectedIndex = 0; });
                    break;

            }
        }
    }
}